package com.android.demo.notepad1;

import android.graphics.Color;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.widget.EditText;

public class Utils {
	
	public static void setStrikedText(StrikethroughSpan strikeSpan, EditText editText, String text) {
		if(text!=null) {
			editText.setText(text);
		}
		Spannable spannable = (Spannable) editText.getText();
		spannable.setSpan(new ForegroundColorSpan(Color.GRAY), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		spannable.setSpan(strikeSpan, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		editText.setText(spannable);		
	}
	
	public static void removeStrikedText(StrikethroughSpan strikeSpan, EditText editText, String text) {
		if(text!=null) {
			editText.setText(text);
		}
		Spannable spannable = (Spannable) editText.getText();
		spannable.setSpan(new ForegroundColorSpan(Color.BLACK), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		spannable.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		spannable.removeSpan(strikeSpan);
		editText.setText(editText.getText());		
	}

}
